//
//  WXPSettingVC.m
//  MexicoLoan
//
//  Created by wxp on 2025/2/27.
//

#import "WXPSettingVC.h"

@interface WXPSettingVC ()

@property (nonatomic, strong) WXPNavView * navView;
@property (nonatomic, strong) UIView * viewContent;
@property (nonatomic, strong) UIButton * btnReal;
@property (nonatomic, strong) UIButton * btnVersion;
@property (nonatomic, strong) UIButton * btnLogout;
@property (nonatomic, strong) WXPCommonAgreementView * agreementView;

@end

@implementation WXPSettingVC

#pragma mark - lazy
- (WXPNavView *)navView{
    if (!_navView) {
        _navView = [WXPNavView new];
        [_navView resetViewWithTitle:@"Configurar"];
    }
    return _navView;
}
- (WXPCommonAgreementView *)agreementView{
    if (!_agreementView) {
        _agreementView = [WXPCommonAgreementView new];
        _agreementView.centerXBottom = XY(SCREEN_WIDTH/2, SCREEN_HEIGHT-LEFT_MARDIN);
    }
    return _agreementView;
}
- (UIView *)viewContent{
    if (!_viewContent) {
        _viewContent = [UIView new];
        _viewContent.userInteractionEnabled = true;
        _viewContent.backgroundColor = COLOR_WHITE;
        [GlobalMethod setRoundView:_viewContent color:[UIColor clearColor] numRound:16 width:0];
    }
    return _viewContent;
}
- (UIButton *)btnReal{
    if (_btnReal == nil) {
        _btnReal = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnReal.tag = 1;
        [_btnReal addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btnReal.widthHeight = XY(self.tableView.width, Ratio(47));
        UILabel * titleLabel = [UILabel new];
        titleLabel.textColor = COLOR_BLACK;
        titleLabel.fontNum = 12;
        [titleLabel fitTitle:@"Realimentación" variable:0];
        [_btnReal addSubview:titleLabel];
        titleLabel.leftCenterY = XY(16, _btnReal.height/2);
        UIImageView * image = [UIImageView new];
        image.image = [UIImage imageNamed:@"icon-arrow-detail"];
        image.widthHeight = XY(14, 14);
        [_btnReal addSubview:image];
        image.rightCenterY = XY(_btnReal.width-titleLabel.left, _btnReal.height/2);
    }
    return _btnReal;
}
- (UIButton *)btnVersion{
    if (_btnVersion == nil) {
        _btnVersion = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnVersion.widthHeight = XY(self.tableView.width, Ratio(47));
        UILabel * titleLabel = [UILabel new];
        titleLabel.textColor = COLOR_BLACK;
        titleLabel.fontNum = 12;
        [titleLabel fitTitle:@"Número de versión" variable:0];
        [_btnVersion addSubview:titleLabel];
        titleLabel.leftCenterY = XY(16, _btnVersion.height/2);
        
        UILabel * versiLabel = [UILabel new];
        versiLabel.textColor = COLOR_LIGHT_GRAY;
        versiLabel.fontNum = 12;
        NSString * currentVersion = [GlobalMethod getVersion];
        [versiLabel fitTitle:[NSString stringWithFormat:@"Versi %@",currentVersion] variable:0];
        [_btnVersion addSubview:versiLabel];
        versiLabel.rightCenterY = XY(_btnVersion.width-titleLabel.left, _btnVersion.height/2);
    }
    return _btnVersion;
}
- (UIButton *)btnLogout{
    if (_btnLogout == nil) {
        _btnLogout = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnLogout.tag = 2;
        [_btnLogout addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btnLogout.backgroundColor = COLOR_PRIMARY;
        _btnLogout.titleLabel.fontNum = 14;
        [_btnLogout setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnLogout.widthHeight = XY(self.tableView.width-2*LEFT_MARDIN, BUTTON_HEIGHT);
        [GlobalMethod setRoundView:_btnLogout color:[UIColor clearColor] numRound:_btnLogout.height/2 width:0];
        [_btnLogout setTitle:@"Cerrar sesión" forState:(UIControlStateNormal)];
    }
    return _btnLogout;
}

#pragma mark - viewDidLoad
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    // 打点
    [GlobalMethod hitPointWithPageName:KEY_Settings action:KEY_Enter extInfo:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configUI];
}

#pragma mark - configUI
- (void)configUI{
    self.view.backgroundColor = COLOR_BACKGROUND;
    self.viewBG.backgroundColor = COLOR_BACKGROUND;
    self.tableHeaderTopBg.backgroundColor = [UIColor clearColor];
    self.tableView.backgroundColor = COLOR_WHITE;
    [self.view addSubview:self.navView];
    [self.view addSubview:self.agreementView];
    
    self.tableView.height = self.agreementView.top-10-self.navView.bottom-10;
    self.tableView.width = SCREEN_WIDTH-2*LEFT_MARDIN;
    [GlobalMethod setRoundView:self.tableView color:COLOR_WHITE numRound:16 width:0];
    self.tableView.centerXTop = XY(SCREEN_WIDTH/2, self.navView.bottom+10);
    

    self.viewContent.widthHeight = XY(self.tableView.width, 0);
    self.tableView.tableHeaderView = self.viewContent;
    
    self.btnReal.centerXTop = XY(self.viewContent.width/2, LEFT_MARDIN);
    [self.viewContent addSubview:self.btnReal];
    self.btnVersion.centerXTop = XY(self.viewContent.width/2, self.btnReal.bottom);
    [self.viewContent addSubview:self.btnVersion];
    self.btnLogout.centerXTop = XY(self.viewContent.width/2, self.btnVersion.bottom+50);
    [self.viewContent addSubview:self.btnLogout];
    self.viewContent.height = self.btnLogout.bottom+20;
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    [NSObject clickFeedback];
    [sender addClickAnimate];
    switch (sender.tag) {
        case 1:
        {
            [Global_Nav pushVCName:@"WXPFeedBackVC" animated:true];
        }
            break;
        case 2:
        {
            //退出登录
            [RequestApi requestLogoutWithDelegate:self success:^(NSDictionary * _Nonnull response, id  _Nonnull mark) {
                [GlobalMethod logoutSuccess];
            } failure:^(NSString * _Nonnull errorStr, id  _Nonnull mark) {
                
            }];
        }
            break;
        default:
            break;
    }
}

@end
